package com.icart.repositories;


import com.icart.entities.MkSaleinfoEntity;
import org.springframework.context.annotation.Scope;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Scope("prototype")
public interface MksaleinfoRepository extends BaseRepository<MkSaleinfoEntity,Integer> {
    @Transactional
    @Query(nativeQuery = true,value = "insert into mk_saleinfo(oid,chnid,custid,servitem,custcar,carno,cartype,createtime,remark,stat,staffid,waternum) values(?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12)")
    @Modifying(clearAutomatically = true)

    Integer insert(String oid, Long chnid, Long custid,Long servitem, Long custcar, String carno,String cartype,String createtime,String remark,int stat,Long staffid,String waternum);

    @Query(nativeQuery = true,value = "select * from mk_saleinfo where oid=?1")
    MkSaleinfoEntity saleinfo(String oid);

    @Transactional
    @Query(nativeQuery = true,value = "update mk_saleinfo set carno=?1,remark=?2,servitem=?3,waternum=?4 where oid=?5")
    @Modifying(clearAutomatically = true)

    Integer update(String carno,String remark,Long servitem,String waternum,String oid);

    @Transactional
    @Query(nativeQuery = true,value = "update mk_saleinfo set stat=0,completetime=?1 where oid=?2")
    @Modifying(clearAutomatically = true)

    Integer updatestat(String completetime,String oid);

    @Query(nativeQuery = true,value = "select max(oid) curoid from mk_saleinfo where oid like ?1")
    String findmaxid(String day);
}
